package com.fjut.kms.dao;

import com.fjut.kms.domain.Parameters;
import com.fjut.kms.tools.DBTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Empathy on 2017/8/16.
 */
public class ParametersJDBCImpl implements ParametersDao {
    private static final String SQL="select paraValue from parameters where paraName=?";
    public List<Parameters> getParametersList(String paraName){
        Connection conn= DBTools.getConn();
        PreparedStatement pstmt=null;
        ResultSet rset=null;
        List<Parameters> paraList=new ArrayList<Parameters>();
        try{
            pstmt=conn.prepareStatement(SQL);
            pstmt.setString(1,paraName);
            rset=pstmt.executeQuery();
            while (rset.next()){
                Parameters para=new Parameters();
                para.setParaValue(rset.getString("paraValue"));
                paraList.add(para);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBTools.releaseRes(conn,pstmt,null);
        }
        return paraList.size()>0?paraList:null;
    }
}
